/* import 'nprogress/nprogress.css'; // progress bar style

import NProgress from 'nprogress'; // progress bar
import { MessagePlugin } from 'tdesign-vue-next';
import { RouteRecordRaw } from 'vue-router';

import { TOKEN_NAME } from '@/config/global'; */
import router from '@/router';
/* import { getPermissionStore, getUserStore } from '@/store';
import { PAGE_NOT_FOUND_ROUTE } from '@/utils/route/constant'; // 404 
NProgress.configure({ showSpinner: false }); */

router.beforeEach(async (to, from, next) => {
  next();
  /*  NProgress.start();

  const permissionStore = getPermissionStore(); // 获取路由
  const { whiteListRouters } = permissionStore; // 白名单路由 

  const userStore = getUserStore(); // 获取用户信息
  const { token } = userStore;
  const token = localStorage.getItem(TOKEN_NAME); // 获取token

  if (token) {
    if (to.path === '/login') {
      next({
        path: '/',
      });
      return;
    }
    const { asyncRoutes } = permissionStore; // 获取路由
    if (asyncRoutes && asyncRoutes.length === 0) {
      const routeList = await permissionStore.buildAsyncRoutes();
      routeList.forEach((item: RouteRecordRaw) => {
        router.addRoute(item);
      });

      if (to.name === PAGE_NOT_FOUND_ROUTE.name) {
        // 动态添加路由后，此处应当重定向到fullPath，否则会加载404页面内容
        next({ path: to.fullPath, replace: true, query: to.query });
      } else {
        const redirect = decodeURIComponent((from.query.redirect || to.path) as string);
        next(to.path === redirect ? { ...to, replace: true } : { path: redirect });
        return;
      }
    }
    // 获取用户信息
    try {
      await userStore.getUserInfo();

      if (router.hasRoute(to.name)) {
        next();
      } else {
        next(`/`);
      }
    } catch (error) {
      MessagePlugin.error(error);
      next({
        path: '/login',
        query: { redirect: encodeURIComponent(to.fullPath) },
      });
      NProgress.done();
    }
  } else {
    // 白名单
    if (whiteListRouters.indexOf(to.path) !== -1) {
      next();
    } else {
      next({
        path: '/login',
        query: { redirect: encodeURIComponent(to.fullPath) },
      });
    }
    NProgress.done();
  } */
});

router.afterEach(() => {
  // if (to.path === '/login') {
  //   const userStore = getUserStore();
  //   const permissionStore = getPermissionStore();
  //
  //   // userStore.logout();
  //   permissionStore.restoreRoutes();
  // }
  // NProgress.done();
});
